package com.spark.common

import com.spark.common.ext.wrapIO
import com.spark.common.net.Http
import com.spark.common.net.toFileBody
import com.spark.common.net.toJsonBody
import io.reactivex.Observable

object Api {
    /**
     * 标准化资料
     */
    // 资料检索
    fun getEditionList(scopedContentId: String = "", keywords: String = "", brands: String = "", startTime: String = "", endTime: String = "", page: String = "1"): Observable<String> {
        val params = mutableMapOf(
                Const.qr_scopeContentId to scopedContentId,
                Const.qr_keyswords to keywords,
                Const.qr_brands to brands,
                Const.qr_startTime to startTime,
                Const.qr_endTime to endTime,
                Const.qr_pageNum to page,
                Const.qr_pageSize to "10"
        )

        return Http.request()
                .rxPost("${Const.base_url}${Const.act_material_query}", params.toJsonBody())
                .wrapIO()

    }

    /**
     * 上传图片
     */
    fun upload(src: String): Observable<String> {
        return Http.request()
                .rxUpload("${Const.base_url}${Const.act_upload}", src.toFileBody("image"))
                .wrapIO()
    }

    /**
     * 删除图片
     */

    fun delImg(taskId: String, dockFlag: String): Observable<String> {
        val params = mutableMapOf(
                "taskId" to taskId,
                "docFlag" to dockFlag
        )
        return Http.request()
                .rxPost("${Const.base_url}${Const.act_del_img}", params.toJsonBody())
                .wrapIO()
    }
}